class LoadingUI extends egret.Sprite {

    public constructor() {
        super();
        this.createView();
    }

    private textField: egret.TextField;
    private barBg;
    private bar;

    private createView(): void {
        //添加背景
        RES.getResByUrl("resource/assets/bg_shuiwen.png", function (texture) {
            var bg1 = new egret.Bitmap();
            bg1.texture = texture;
            this.addChildAt(bg1, 0);
            var bg2 = new egret.Bitmap();
            bg2.texture = texture;
            this.addChildAt(bg2, 0);
            // bg1.x=-560;
            // bg2.x=-560;
            // bg2.y=-1136;
            // egret.Tween.get(bg1, { loop: true }).to({ x: 0, y: 1136 }, 10000);
            // egret.Tween.get(bg2, { loop: true }).to({ x: 0, y: 0 }, 10000);
        }, this);

        //添加背景
        var bg = drawReactShape(null, 0, 0, 640, 1136, 0x16c5ee);
        this.addChild(bg);


        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 500;
        this.textField.width = 640;
        this.textField.height = 100;
        this.textField.textAlign = "center";


        
        

        

        this.barBg = new egret.Shape();
        this.barBg.graphics.beginFill(0x000000);
        this.barBg.graphics.drawRect(120, 530, 400, 20);
        this.barBg.graphics.endFill();
        this.addChild(this.barBg);

        this.bar = new egret.Shape();
        this.bar.graphics.beginFill(0xffffff);
        this.bar.graphics.drawRect(120, 530, 0, 20);
        this.bar.graphics.endFill();
        this.addChild(this.bar);

    }

    public setProgress(current: number, total: number): void {
        var percent = Math.ceil(current / total * 400);
        var percent1 = Math.ceil(current / total * 100);
        this.textField.text = `Loading...${percent1}%`;
        this.bar.graphics.beginFill(0xffffff);
        this.bar.graphics.drawRect(120, 530, percent, 20);
        this.bar.graphics.endFill();
    }
}
